package com.hmall.item.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hmall.item.pojo.Item;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 商品mapper
 */
@Repository
public interface ItemMapper extends BaseMapper<Item> {

    /**
     * @return
     */
    @Select("select * from tb_item limit #{index}, #{size}")
    List<Item> findItemByPage(@Param("index") Integer index, @Param("size") Integer size);

    //查询总条数
    @Select("select count(*) from tb_item")
    Long findAllItems();

    //首先根据id查询商品信息
    @Select("select * from tb_item where id=#{id}")
    Item findItemById(@Param("id") Long id);

    /**
     * 修改商品状态值
     */
    @Update("update tb_item set status=#{status} where id=#{id}")
    void updateStatus(@Param("id") Long id,@Param("status") Integer status);
}
